package edu.jptest.serviceImp;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import edu.jptest.bean.QuestionOrigin;
import edu.jptest.dao.QuestionOriginDAO;
import edu.jptest.service.IQuestionOriginService;
import edu.jptest.util.UnitLesson;

public class QuestionOriginService implements IQuestionOriginService {

	// 插入来源question_origin,textbook_name,unit,lesson
	public boolean insertQuestionOrigin(QuestionOrigin questionOrigin) {
		QuestionOriginDAO questionorigindao = new QuestionOriginDAO();
		return questionorigindao.insertQuestionOrigin(questionOrigin);
	}

	// 删除来源Դ
	public boolean deleteQuestionOrigin(int questionOriginId) {
		QuestionOriginDAO questionorigindao = new QuestionOriginDAO();
		return questionorigindao.deleteQuestionOrigin(questionOriginId);
	}

	//通过教材名删除教材
	public boolean deleteQuestionOriginByBookName(String bookName){
		QuestionOriginDAO questionorigindao = new QuestionOriginDAO();
		return questionorigindao.deleteQuestionOriginByBookName(bookName);
	}
	
	// 修改来源
	public boolean updateQuestionOrigin(QuestionOrigin questionOrigin) {
		QuestionOriginDAO questionorigindao = new QuestionOriginDAO();
		return questionorigindao.updateQuestionOrigin(questionOrigin);
	}

	// 通过来源id，查询来源对象
	public QuestionOrigin getQuestionOriginByQuestionOriginId(
			int questionorigin_id) {
		QuestionOriginDAO questionorigindao = new QuestionOriginDAO();
		return questionorigindao
				.getQuestionOriginByQuestionOriginId(questionorigin_id);
	}

//	// 通过教材、单元，获得来源id
//	public int getQuestionOriginIdByBookNameAndUnit(String book_name, int unit) {
//		QuestionOriginDAO questionorigindao = new QuestionOriginDAO();
//		return questionorigindao.getQuestionOriginIdByBookNameAndUnit(
//				book_name, unit);
//	}

	// 通过教材、课别，获得来源id
	public int getQuestionOriginIdByBookNameAndLesson(String book_name,
			int lesson) {
		QuestionOriginDAO questionorigindao = new QuestionOriginDAO();
		return questionorigindao.getQuestionOriginIdByBookNameAndLesson(
				book_name, lesson);
	}

	// 获得所有教材�
	public List<String> getAllBooksName() {
		QuestionOriginDAO questionorigindao = new QuestionOriginDAO();
		return questionorigindao.getAllBooks();
	}

	// 获得教材单元和课别的对应关系
	public List<UnitLesson> getUnitLesson(String book_name) {
		QuestionOriginDAO questionOriginDao = new QuestionOriginDAO();
		return questionOriginDao.getUnitLesson(book_name);
	}

	// �õ�获得某教材中的单元数�Ԫ
	public int getUnitNum(String book_name) {
		QuestionOriginDAO questionorigindao = new QuestionOriginDAO();
		return questionorigindao.getUnitsByBook(book_name);
	}

	// 获得某教材中的课数
	public int getLessonNum(String book_name) {
		QuestionOriginDAO questionorigindao = new QuestionOriginDAO();
		return questionorigindao.getLessonsByBook(book_name);
	}

	// 获得某教材中、某单元的课数�
	public List<Integer> getAllLessons(String book_name, int unit) {
		QuestionOriginDAO questionorigindao = new QuestionOriginDAO();
		int lesson = questionorigindao.getLessonsByBookAndBookName(book_name,
				unit);
		List<Integer> lessons = new ArrayList<Integer>();
		for (int i = 1; i < lesson; i++) {
			lessons.add(i);
		}
		return lessons;
	}
	
	// 获得某本教材的单元和课别列表
	public List<QuestionOrigin> getUnitLessonList(String book_name){
		QuestionOriginDAO questionorigindao = new QuestionOriginDAO();
		return questionorigindao.getUnitLessonList(book_name);
	}
}
